From: Magnus Manske Date: Wed, 29 Dec 2004 13:46:10 +0000 (+0000) Subject: separate metadata editor, pre-alpha X-Git-Tag: 1.5.0alpha1~1009 X-Git-Url: http://git.cyclocoop.org/%28%5B%5E/404?a=commitdiff_plain;h=3eccb2240373f5365e9729417ca59ea9a2bcb16c;p=lhc%2Fweb%2Fwiklou.git separate metadata editor, pre-alpha --- diff --git a/includes/EditPage.php b/includes/EditPage.php index a8e66e311b..d1ac778516 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -16,6 +16,7 @@ class EditPage { var $mArticle; var $mTitle; + var $mMetaData = ''; # Form values var $save = false, $preview = false; @@ -34,6 +35,80 @@ class EditPage { $this->mTitle =& $wgTitle; } + /** + * This is the function that extracts metadata from the article body on the first view. + * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings + */ + function extractMetaDataFromArticle () + { + global $wgUseMetadataEdit , $wgLang ; + $this->mMetaData = "" ; + if ( !$wgUseMetadataEdit ) return ; + $s = "" ; + $t = $this->mArticle->getContent ( true ) ; + + # MISSING : filtering + + # Categories and language links + $t = explode ( "\n" , $t ) ; + $catlow = strtolower ( $wgLang->getNsText ( NS_CATEGORY ) ) ; + $cat = $ll = array() ; + foreach ( $t AS $key => $x ) + { + $y = trim ( strtolower ( $x ) ) ; + while ( substr ( $y , 0 , 2 ) == "[[" ) + { + $y = explode ( "]]" , trim ( $x ) ) ; + $first = array_shift ( $y ) ; + $first = explode ( ":" , $first ) ; + $ns = array_shift ( $first ) ; + $ns = trim ( str_replace ( "[" , "" , $ns ) ) ; + if ( strlen ( $ns ) == 2 OR strtolower ( $ns ) == $catlow ) + { + $add = "[[" . $ns . ":" . implode ( ":" , $first ) . "]]" ; + if ( strtolower ( $ns ) == $catlow ) $cat[] = $add ; + else $ll[] = $add ; + $x = implode ( "]]" , $y ) ; + $t[$key] = $x ; + $y = trim ( strtolower ( $x ) ) ; + } + } + } + if ( count ( $cat ) ) $s .= implode ( " " , $cat ) . "\n" ; + if ( count ( $ll ) ) $s .= implode ( " " , $ll ) . "\n" ; + $t = implode ( "\n" , $t ) ; + + # Templates, but only some + $sat = array ( "meta-template" ) ; # stand-alone-templates; must be lowercase + $t = explode ( "{{" , $t ) ; + $tl = array () ; + foreach ( $t AS $key => $x ) + { + $y = explode ( "}}" , $x , 2 ) ; + if ( count ( $y ) == 2 ) + { + $z = $y[0] ; + $z = explode ( "|" , $z ) ; + $tn = array_shift ( $z ) ; + if ( in_array ( strtolower ( $tn ) , $sat ) ) + { + $tl[] = "{{" . $y[0] . "}}" ; + $t[$key] = $y[1] ; + $y = explode ( "}}" , $y[1] , 2 ) ; + } + else $t[$key] = "{{" . $x ; + } + else if ( $key != 0 ) $t[$key] = "{{" . $x ; + else $t[$key] = $x ; + } + if ( count ( $tl ) ) $s .= implode ( " " , $tl ) ; + $t = implode ( "" , $t ) ; + + $t = str_replace ( "\n\n\n" , "\n" , $t ) ; + $this->mArticle->mContent = $t ; + $this->mMetaData = $s ; + } + /** * This is the function that gets called for "action=edit". */ @@ -77,6 +152,7 @@ class EditPage { if( $wgUser->getOption('previewonfirst') ) { $this->editForm( 'preview', true ); } else { + $this->extractMetaDataFromArticle () ; $this->editForm( 'initial', true ); } } @@ -91,6 +167,7 @@ class EditPage { # whitespace from the text boxes. This may be significant formatting. $this->textbox1 = rtrim( $request->getText( 'wpTextbox1' ) ); $this->textbox2 = rtrim( $request->getText( 'wpTextbox2' ) ); + $this->mMetaData = rtrim( $request->getText( 'metadata' ) ); $this->summary = trim( $request->getText( 'wpSummary' ) ); $this->edittime = $request->getVal( 'wpEdittime' ); @@ -159,6 +236,10 @@ class EditPage { # in the back door with a hand-edited submission URL. if ( 'save' == $formtype ) { + # Reintegrate metadata + if ( $this->mMetaData != "" ) $this->textbox1 .= "\n" . $this->mMetaData ; + $this->mMetaData = "" ; + # Check for spam if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1, $matches ) ) { $this->spamPage ( $matches[0] ); @@ -478,17 +559,29 @@ class EditPage { $liveOnclick = ''; } + global $wgUseMetadataEdit ; + if ( $wgUseMetadataEdit ) + { + $metadata = $this->mMetaData ; + $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ; + $metadata = "" ; + } + else $metadata = "" ; + + $wgOut->addHTML( << {$commentsubject} +{$mbegin} +{$metadata}
{$editsummary} {$checkboxhtml} textbox1 = $this->mArticle->getContent(true); } - $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $this->textbox1 ) ."\n\n", + $toparse = $this->textbox1 ; + if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData ; + + $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ) ."\n\n", $wgTitle, $parserOptions ); $previewHTML = $parserOutput->mText;